package cn.middle.remote.server;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import cn.middle.remote.handler.business.ProcessingHandler;
import cn.middle.remote.serialization.Serialization;

public abstract class ServerProcessingHandler implements ProcessingHandler {
	
	/**
	 * 鉴权
	 */
	protected LoginAuthHandler authHandler;
	
	/**
	 * 数据监听
	 */
	protected ServerListener listener;
	
	protected Serialization serialization;
	
	
	public Serialization getSerialization() {
		return serialization;
	}

	/**
	 * 设置序列化处理器
	 * @param serialization
	 */
	public void setSerialization(Serialization serialization) {
		this.serialization = serialization;
	}

	protected Map<Integer,Session> CLIENTS = new ConcurrentHashMap<>();
	
	
	public List<Session> getSessions() {
		List<Session> sessions = new ArrayList<>(CLIENTS.values());
		return sessions;
	}
	
	public Session getClientId(Integer clientId) {
		return CLIENTS.get(clientId);
	}
	/**
	 * 添加鉴权处理器
	 * @param authHandler
	 */
	public void setLoginAuthHandler(LoginAuthHandler authHandler) {
		this.authHandler = authHandler;
	}
	
	/**
	 * 添加数据监听器
	 * @param listener
	 */
	public void setReceivedListener(ServerListener listener) {
		this.listener = listener;
	}
	
	/**
	 * 擦除缓存数据
	 */
	public abstract void clearUp();

}
